package com.zg.monitor.os.vo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zg.monitor.common.util.LayoutUtil;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author Zxb
 */
@Data
@Builder
@Accessors(chain = true)
public class Server {
    /**
     * 主机名
     */
    private String hostName;

    /**
     * 操作系统名称
     */
    private String osName;

    /**
     * 操作系统版本
     */
    private String osVersion;

    /**
     * 系统架构
     */
    private String arch;

    /**
     * 本地IP
     */
    private String localIp;

    @Override
    public String toString() {
        return LayoutUtil.Table.of(
                LayoutUtil.Row.of("HostName", hostName),
                LayoutUtil.Row.of("OS", osName + "/" + osVersion),
                LayoutUtil.Row.of("Arch", arch),
                LayoutUtil.Row.of("LocalIp", localIp)
        ).toString();
    }

    public JSONArray toJSON() {
        JSONArray ja = new JSONArray();
        JSONObject jo = new JSONObject();
        jo.put("hostName", hostName);
        jo.put("os", osName + "/" + osVersion);
        jo.put("arch", arch);
        jo.put("localIp", localIp);
        ja.add(jo);
        return ja;
    }
}
